using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel;

namespace ERPBackend.Models
{
    public class PurchaseOrder : BaseModel
    {
        [Required]
        [StringLength(50)]
        public string OrderCode { get; set; } = string.Empty;

        [Required]
        public int SupplierId { get; set; }

        [ForeignKey("SupplierId")]
        public Supplier? Supplier { get; set; }

        [Required]
        public DateOnly OrderDate { get; set; }

        public DateOnly? ExpectedDeliveryDate { get; set; }

        public DateOnly? ActualDeliveryDate { get; set; }

        [Required]
        [DefaultValue(0)]
        public byte Status { get; set; } = 0; // 0: 待审核, 1: 已审核, 2: 已完成, 3: 已关闭, 4: 已取消

        [StringLength(255)]
        public string? PaymentTerms { get; set; }

        [StringLength(100)]
        public string? DeliveryMethod { get; set; }

        [StringLength(100)]
        public string? FreightResponsibility { get; set; }

        [Required]
        [Column(TypeName = "decimal(18, 2)")]
        public decimal TotalAmount { get; set; } = 0;

        [Column(TypeName = "decimal(18, 2)")]
        public decimal PaidAmount { get; set; } = 0;

        [Column(TypeName = "decimal(18, 2)")]
        public decimal UnpaidAmount { get; set; } = 0;

        [Required]
        public int CreatedBy { get; set; }

        [Required]
        public DateTime CreatedAt { get; set; } = DateTime.Now;

        public int? UpdatedBy { get; set; }

        public DateTime? UpdatedAt { get; set; }

        public int? ReviewedBy { get; set; }

        public DateTime? ReviewedAt { get; set; }

        public int? ClosedBy { get; set; }

        public DateTime? ClosedAt { get; set; }

        [StringLength(500)]
        public string? CloseReason { get; set; }

        // 导航属性
        public ICollection<PurchaseOrderItem>? PurchaseOrderItems { get; set; }
    }
}